package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.saas.constant.StringConstant;
import lombok.Getter;

import java.util.Objects;

/**
 * @author haibin.zhang
 * @version v1.0
 * @time 2019/8/27 10:54
 * @since v1.0
 */
@Getter
public enum ServicePrintHelpEnum {

    //新建编辑显示
    SERVICE_NAME("text_1","name","enum.serviceProject.attrName.name"),
    SERVICE_NO(XbbRefTypeEnum.SERVICE_PROJECT.getCode() +",serialNo","serialNo","enum.serviceProject.attrName.serialno"),
    SERIAL_NO("serialNo","serialNo","enum.serviceProject.attrName.serialno"),
    UNIT("text_2","unit","enum.serviceProject.attrName.unit"),
    PRICE("num_1","price","enum.serviceProject.attrName.price"),
    COST("num_2","cost","enum.serviceProject.attrName.cost"),
    SUBTOTAL("num_15","subtotal","enum.serviceProject.attrName.cost"),
    ;

    private String newAttr;

    private String oldAttr;

    private String attrName;



    ServicePrintHelpEnum(String newAttr, String oldAttr, String attrName) {
        this.newAttr = newAttr;
        this.oldAttr = oldAttr;
        this.attrName = attrName;
    }

    public static String getOldAttrByNewAttr(String newAttr){
        for (ServicePrintHelpEnum servicePrintHelpEnum : ServicePrintHelpEnum.values()){
            if (Objects.equals(newAttr,servicePrintHelpEnum.getNewAttr())){
                return servicePrintHelpEnum.getOldAttr();
            }
        }
        return null;
    }

    public static ServicePrintHelpEnum getByNewAttrContact(String attr) {
        for (ServicePrintHelpEnum servicePrintHelpEnum : ServicePrintHelpEnum.values()){
            String newAttr = XbbRefTypeEnum.SERVICE_PROJECT.getCode() + StringConstant.COMMA + attr;
            if (Objects.equals(servicePrintHelpEnum.getNewAttr(), newAttr)){
                return servicePrintHelpEnum;
            }
        }
        return null;
    }

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }
}
